//
//  ProfileEditingViewController.m
//  phonebook
//
//  Created by ming on 10/2/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "RootViewController.h"
#import "ProfileEditingViewController.h"
#import "RecordManager.h"

//#define filePath [NSHomeDirectory() stringByAppendingPathComponent:@"/Users/ASUuser/Desktop/phonebook/phonebook/names.plist"]



@implementation ProfileEditingViewController
@synthesize nameField;
@synthesize numberField;
@synthesize addressField;
@synthesize row_PP;
//@synthesize contactName;

-(void) dealloc {
    [nameField release];
    [numberField release];
    [addressField release];
    [super dealloc];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
//    NamesEditing=[NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"names" ofType:@"plist"]];
//    [NamesEditing retain];

    NamesEditing = [[RecordManager sharedManager] names];
    
    //int row_PP=row_P.text;
    NSDictionary *name=[NamesEditing objectAtIndex:row_PP];
    record = name;
    
    NSString *NameName=[name objectForKey:@"name"];
    NSString *PhoneNumber=[name objectForKey:@"phone number"];
    NSString *Address=[name objectForKey:@"note"];
    //NSString *ImageV=[name objectForKey:@"imageview"];
    
    
    
    //self.picture.image=[UIImage imageNamed:ImageV];
    
    //self.contactName.text=NameName;
    self.nameField.text=NameName;
    self.numberField.text=PhoneNumber;
    self.addressField.text=Address;
}




- (IBAction)profileDonePressed{ 
    
    //NSMutableDictionary *record = [[NSMutableDictionary alloc] init];
    
    // set values from text fields in record
    
    //[plistDict setValue:@"1.1.1" forKey:@"ProductVersion"];
    //[plistDict writeToFile:filePath atomically: YES];
    
    
    //[[RecordManager sharedManager] saveRecords]
   // RecordManager *detail = [[RecordManager alloc] initWithNibName:@"RecordManager" bundle:nil];
   // detail.records=record;

    [record setValue:self.nameField.text forKey:@"name"];
    [record setValue:self.numberField.text forKey:@"phone number"];
    [record setValue:self.addressField.text forKey:@"note"];
    
    
    //RecordManager *managerPoint = [[RecordManager alloc] init];
    //[managerPoint saveRecords];
    //RootViewController *backToRoot = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]];
    
    
    
    //[[self navigationController] pushViewController:backToRoot animated:YES];
    
    [[self navigationController] popToRootViewControllerAnimated:YES];    
    
    
}


-(IBAction)textFieldDone:(id)sender {
    [sender resignFirstResponder];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
